package com.ncepu.clubmanagement.mapper;

import com.ncepu.clubmanagement.pojo.BasePerson;
import com.ncepu.clubmanagement.pojo.Person;
import com.ncepu.clubmanagement.pojo.PersonBasicInfo;
import com.ncepu.clubmanagement.pojo.PersonFontOfGetDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface PersonMapper {


    @Select("select * from person where account = #{account} and password = #{password}")
    public Person selectByAccountAndPassword(Person person);


    @Insert("insert into person(account,password,user_name,email,phone_num,sch_id,sex,head_image)" +
            "values(#{account},#{password},#{userName},#{email},#{phoneNum},#{schId},#{sex},#{headImage})")
    void insert(Person person);

    @Select("select id, account, user_name, email, sch_id, sex, head_image, phone_num from person where account = #{account}")
    Person selectByAccountWithoutPassword(String account);


    @Select("select id from person where account = #{account}")
    int selectIdByAccount(String account);

    void updatePersonInfo(Person person);


    List<BasePerson> selectIdAndNameByName(String name);

    @Select("select head_image from person where account = #{account}")
    String selectHeadImageByAccount(String account);

    @Update("update person set head_image = #{url} where account = #{account}")
    int updatePersonImage(String url, String account);

    @Select("select password from person where account = #{account}")
    String selectPasswordByAccount(String account);

    @Update("update person set password = #{newPassword} where account = #{account}")
    void updatePasswordByAccount(String newPassword, String account);


    @Select("select sch_id from person where id = #{personId}")
    Integer selectSchIdByPersonId(Integer personId);

    List<PersonBasicInfo> selectPersonBasicInfoList(Integer clubId, String userName);

    List<PersonBasicInfo> selectPersonBasicInfoListByClubIdsAndUserName(List<Integer> clubIds, String userName);

    @Update("update person set password = #{password} where id = #{personId}")
    void updatePasswordById(Integer personId, Integer password);

    @Select("select account, password, user_name, email, sch_name, sex, head_image, phone_num from person p " +
            "Left JOIN school s on p.sch_id = s.sch_id where id = #{targetPersonId}")
    PersonFontOfGetDetail selectPersonFontOfGetDetailById(Integer targetPersonId);
}
